package com.abraxascorp.resources;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.abraxascorp.responses.LocationAddResponse;
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;
import com.google.gson.Gson;

public class LocationResourceTest {
	
	private static LocationResource resource;
	private static final Gson gson = new Gson();
	private final LocalServiceTestHelper helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());  
	
	@BeforeClass
    public static void setUpClass() {
		resource = new LocationResource();
    }
	
	@Before  
	public void setUp() {  
		helper.setUp();
	}  
	   
     @After  
     public void tearDown() {  
         helper.tearDown();  
     }  
	
	@Test
	public void testAddWithEmptyParameters() throws Exception {
		String contact = "";
		String profilePicUrl = "";
		String latitude = "";
		String longitude = "";
		String description = "";
		
		// test adding with no contact
		LocationAddResponse response = gson.fromJson(resource.addLocation(contact, profilePicUrl, latitude, longitude, description),
				LocationAddResponse.class);
		assertFalse(response.isSuccess());
		assertFalse(response.getError().isEmpty());
		
		// test adding with no location
		contact = "Joe";
		response = gson.fromJson(resource.addLocation(contact, profilePicUrl, latitude, longitude, description),
				LocationAddResponse.class);
		assertFalse(response.isSuccess());
		assertFalse(response.getError().isEmpty());
	}
	
	@Test
	public void testAddWithDuplicationLocations() throws Exception {
		String contact = "Joe";
		String profilePicUrl = "http://www.google.com/images/logos/ps_logo2.png";
		String latitude = "35.4";
		String longitude = "36.5";
		String description = "Eat @ Joe's";
		
		// test adding with no contact
		resource.addLocation(contact, profilePicUrl, latitude, longitude, description);
		LocationAddResponse response = gson.fromJson(resource.addLocation(contact, profilePicUrl, latitude, longitude, description),
				LocationAddResponse.class);
		assertFalse(response.isSuccess());
		assertFalse(response.getError().isEmpty());
	}
	
	@Test
	public void testAdd() throws Exception {
		String contact = "Joe";
		String profilePicUrl = "http://www.google.com/images/logos/ps_logo2.png";
		String latitude = "35.4";
		String longitude = "36.5";
		String description = "Eat @ Joe's";
		
		// test adding with no contact
		LocationAddResponse response = gson.fromJson(resource.addLocation(contact, profilePicUrl, latitude, longitude, description),
				LocationAddResponse.class);
		assertTrue(response.isSuccess());
	}

}
